var dbConfig = require('../utils/dbconfig');

//获取商品分类列表
getGoodsTypeList = (req,res) =>{
    console.log('获取商品分类列表')
    let {type,pageNum,pageSize} = req.query
    dbConfig.sqlConnect("SELECT * FROM cates_info where goods_level='0' limit ?,?",[pageNum*1-1,pageSize*1],(err,data)=>{
        if(err){
            console.log('获取商品分类列表失败')
        }else{
            let datalist = data;
            for(var i=0;i<datalist.length;i++){
                datalist[i].children=[{goods_name:'123'}]
                console.log(i)
            }
            dbConfig.sqlConnect("select count(1) total from cates_info where goods_level='0' ",[],(err,data)=>{
                if(err)
                    console.log('统计商品分类失败')
                else{
                    console.log(datalist)
                    res.send({
                        code:200,
                        total:data[0].total,
                        result:datalist
                    })
                }
            })
        }
    })
}

module.exports ={
    getGoodsTypeList
}
